package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EduRegionMapper;
import com.ruoyi.system.domain.EduRegion;
import com.ruoyi.system.service.IEduRegionService;
import com.ruoyi.common.core.text.Convert;

/**
 * 地区Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-04
 */
@Service
public class EduRegionServiceImpl implements IEduRegionService 
{
    @Autowired
    private EduRegionMapper eduRegionMapper;

    /**
     * 查询地区
     * 
     * @param regionId 地区主键
     * @return 地区
     */
    @Override
    public EduRegion selectEduRegionByRegionId(Long regionId)
    {
        return eduRegionMapper.selectEduRegionByRegionId(regionId);
    }

    /**
     * 查询地区列表
     * 
     * @param eduRegion 地区
     * @return 地区
     */
    @Override
    public List<EduRegion> selectEduRegionList(EduRegion eduRegion)
    {
        return eduRegionMapper.selectEduRegionList(eduRegion);
    }

    /**
     * 新增地区
     * 
     * @param eduRegion 地区
     * @return 结果
     */
    @Override
    public int insertEduRegion(EduRegion eduRegion)
    {
        return eduRegionMapper.insertEduRegion(eduRegion);
    }

    /**
     * 修改地区
     * 
     * @param eduRegion 地区
     * @return 结果
     */
    @Override
    public int updateEduRegion(EduRegion eduRegion)
    {
        return eduRegionMapper.updateEduRegion(eduRegion);
    }

    /**
     * 批量删除地区
     * 
     * @param regionIds 需要删除的地区主键
     * @return 结果
     */
    @Override
    public int deleteEduRegionByRegionIds(String regionIds)
    {
        return eduRegionMapper.deleteEduRegionByRegionIds(Convert.toStrArray(regionIds));
    }

    /**
     * 删除地区信息
     * 
     * @param regionId 地区主键
     * @return 结果
     */
    @Override
    public int deleteEduRegionByRegionId(Long regionId)
    {
        return eduRegionMapper.deleteEduRegionByRegionId(regionId);
    }

    /**
     * 查询地区树列表
     * 
     * @return 所有地区信息
     */
    @Override
    public List<Ztree> selectEduRegionTree()
    {
        List<EduRegion> eduRegionList = eduRegionMapper.selectEduRegionList(new EduRegion());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (EduRegion eduRegion : eduRegionList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(eduRegion.getRegionId());
            ztree.setpId(eduRegion.getParentId());
            ztree.setName(eduRegion.getRegionName());
            ztree.setTitle(eduRegion.getRegionName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
